Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

440
Visualizações
Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method

i'm using react native with regex

if i use my code

this error occured

Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.

I want to put an empty value like ' ' in the match if any character other than a number and decimal point is included in my regular expression. If you put "123abc" in the value variable, match returns "123", but if you put "acv" in the value constant, the above error occurs. In this case, how can I put an empty string into the match without generating an error?

 const regex = /\d+(\.\d{1,2})?/;

const value = "abd"
const [match] = regex.exec(value);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can use || operator. in case exec return null it will default to empty string ''.

function getStrings(value) {
  const regex = /\d+(\.\d{1,2})?/;
  const [match] = [regex.exec(value) || ''];
  if(Array.isArray(match))
    return match[0]
  return match
}

console.log(getStrings("abd"))
console.log(getStrings("123abd"))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda